package process;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import abstractclass.AbstractProcess;
import freemarker.template.Template;
import util.StringUilts;

public class MControllerProcess extends AbstractProcess{

	@Override
	public void processJava(String packgerOutPath, String beanName, String path, Object object) {
		path = path+"api"+File.separator;
		File file = new File(path);
		if(!file.exists()){
			file.mkdirs();
		}
        try 
        {
			Template template = configuration.getTemplate(ftlFilePrefix+"mcontroller.ftl");
			Template template2 = configuration.getTemplate(ftlFilePrefix+"murl.ftl");

			Map<String, Object> ParamMap = new HashMap<String, Object>();
            ParamMap.put("packageOutPath", packgerOutPath);
            ParamMap.put("bean", beanName);
            ParamMap.put("lowercaseBean", StringUilts.initLowerCase(beanName));

            Writer writer  = new OutputStreamWriter(new FileOutputStream(path+"M"+beanName+"Controller.java"),"UTF-8"); 
            Writer writer1  = new OutputStreamWriter(new FileOutputStream(path+"Murl.java"),"UTF-8"); 

            template.process(ParamMap, writer);  
            template2.process(ParamMap, writer1); 

			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
}
